/**
     * super simple slideshow
     * animation between slides happens with css transitions
     */
    
//var scroll = new TouchScroll("#overflow");
//scroll.scrollTo(0, 200);
function TouchScroll(container, options)
{
    container = $(container);
    var content = $(">.content", container);
    var scrollbar = $(">.scrollbar div", container);

    var self = this;
    var hammer = new Hammer(container.get(0), {
        drag: true,
        drag_vertical: true,
        drag_horizontal: true,
        drag_min_distance: 0,

        transform: false,
        tap: false,
        tap_double: false,
        hold: false
    });


    function getScrollPosition() {
        return {
            top: parseInt(content.css('top'), 10),
            left: parseInt(content.css('left'), 10)
        };
    }


    /**
         * get the dimensions of a element
         * @param   jQuery  el
         * @return  object  { width: int, height: int }
         */
    function getDimensions( el ) {
        return {
            width: el.outerWidth(),
            height: el.outerHeight()
        };
    }


    /**
         * scroll to given x and y
         * @param   int x
         * @param   int y
         */
    this.scrollTo = function(x, y)
    {

    };


    var scroll_start = {};
    var scroll_dim = {};
    var content_dim = {};

    hammer.ondragstart = function() {
        scroll_start = getScrollPosition();
        scroll_start.time = new Date().getTime();

        scroll_dim = getDimensions( container );
        content_dim = getDimensions( content );

        scrollbar.css({
            height: (100 / content_dim.height * scroll_dim.height) * (scroll_dim.height/100)
        }).stop().fadeTo(80, 1);
    };


    hammer.ondrag = function( ev ) {
        if(ev.direction == 'up' || ev.direction == 'left') {
            ev.distance = 0-ev.distance;
        }

        var delta = 1;

        var top = scroll_start.top + ev.distance * delta;
        content.css({
            top: top
        });

        scrollbar.css({
            top: (100 / content_dim.height) * (0 - top) +"%"
        });
    };


    hammer.ondragend = function( ev ) {
        var scroll = getScrollPosition();
        var corrections = {};
        if(scroll.top > 0) {
            corrections.top = 0;
        }

        else if(scroll.top < -(content_dim.height - scroll_dim.height) ) {
            corrections.top = -(content_dim.height - scroll_dim.height);
        }

        content.animate(corrections, 400);
        scrollbar.stop().animate({
            top: (100 / content_dim.height) * (0 - corrections.top) +"%"
        }, 400);

        scrollbar.stop().fadeTo(80, 0);

    };
}
